using Gateway.Common.Enums;
using Gateway.Domain.EFCore.Configuration;
using Gateway.Domain.Entities;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace Gateway.Domain.Configuration;

public class DataDicConfiguration : AggregateRootEntityConfiguration<DataDic>
{
    public override void Configure(EntityTypeBuilder<DataDic> builder)
    {
        base.Configure(builder);
        builder.ToTable(t => t.HasComment("数据字典"));
        builder.Property(x => x.Name).IsRequired().HasMaxLength(200).HasComment("字典名称");
        builder.Property(x => x.Code).IsRequired().HasMaxLength(200).HasComment("字典编码");
        builder.Property(x => x.Sort).HasComment("排序序号");
        builder.Property(x => x.Description).HasMaxLength(500).HasComment("描述");
        builder.Property(x => x.Value).HasMaxLength(500).HasComment("字典值");
        builder.Property(x => x.ParentId).HasMaxLength(50).HasComment("父级标识");
        builder.Property(x => x.DicType).IsRequired().HasMaxLength(50).HasComment("字典类别")
            .HasConversion(x => x.Value, x => DataDicTypeEnum.FromValue(x));
    }
}